{% extends "base.html" %}
{% load i18n %}
{% load promgen %}

{% block content %}

<div class="page-header promgen-flex-space-between-center" v-pre>
  <div>
    <h1>
      Farm: {{ farm.name }} ({{ farm.source }})
    </h1>
    {% if farm.owner %}
      <p>{% trans "Contact" %}: {{farm.owner.username}}</p>
    {% endif %}
  </div>
  {% if farm.editable %}
    <div>
      <a href="{% url 'farm-update' farm.id %}" class="btn btn-warning btn-sm">{% translate "Edit Farm" %}</a>
      <form method="post" action="{% url 'farm-delete' farm.id %}" onsubmit="return confirm('Delete this farm?')" style="display: inline">
        {% csrf_token %}
        <button class="btn btn-danger btn-sm">Delete Farm</button>
      </form>
    </div>
  {% endif %}
</div>

{% breadcrumb farm %}

<div class="row" v-pre>

<div class="col-md-6">
  <div class="panel panel-default">
    <div class="panel-heading">Hosts</div>
    <table class="table">
    {% for host in farm.host_set.all %}
      <tr>
        <td><a href="{% url 'host-detail' host.name %}">{{ host.name }}</a></td>
        {% if farm.editable %}
        <td style="width: 0; min-width: fit-content;">
          <form method="post" action="{% url 'host-delete' host.id %}" onsubmit="return confirm('Really delete this host?');">
            {% csrf_token %}
          <button name="delete" type="submit" class="btn btn-danger btn-sm">Delete</button>
          </form>
        </td>
        {% endif %}
      </tr>
    {% endfor %}
    </table>

  {% if farm.editable %}
    <div class="panel-footer">
      <a href="{% url 'hosts-add' farm.id %}" class="btn btn-primary">{% trans "Register Hosts" %}</a>
    </div>
  {% endif %}
  </div>
</div>

<div class="col-md-6">
  <div class="panel panel-default">
    <div class="panel-heading">Projects using {{ farm.name }} ({{ farm.source }})</div>
    <table class="table">
{% for project in farm.project_set.all %}
      <tr>
        <td><a href="{% url 'project-detail' project.id %}">{{ project.name }}</a></td>
      </tr>
{% endfor %}
    </table>
  </div>
</div>

</div>

{% endblock %}
